unit SpecialPawnProbability;

interface

uses IniFiles;

type

 TSpecialPawnProbability = class
 private
  Joker: integer;
  Bonus: integer;
  Skull: integer;
  Chameleon: integer;
  Hourglass: integer;
 public
  constructor Create(Joker, Bonus, Skull, Chameleon, Hourglass: integer);
  function GetJokerProbility: integer;
  function GetBonusProbility: integer;
  function GetSkullProbility: integer;
  function GetChameleonProbility: integer;
  function GetHourglassProbility: integer;
  function IsInJokerRange(e: double): boolean;
  function IsInBonusRange(e: double): boolean;
  function IsInSkullRange(e: double): boolean;
  function IsInChameleonRange(e: double): boolean;
  function IsInHourglassRange(e: double): boolean;
  function GetDifficultLevelInPercent: Integer;
  function GetSum: integer;
  procedure SaveSettings(Ini: TIniFile);
  procedure LoadSettings(Ini: TIniFile);
 end;

implementation

procedure TSpecialPawnProbability.SaveSettings(Ini: TIniFile);
begin
 ini.WriteInteger('Probabilities', 'Joker', Joker);
 ini.WriteInteger('Probabilities', 'Bonus', Bonus);
 ini.WriteInteger('Probabilities', 'Skull', Skull);
 ini.WriteInteger('Probabilities', 'Chameleon', Chameleon);
 ini.WriteInteger('Probabilities', 'Hourglass', Hourglass);
 ini.UpdateFile;
end;

procedure TSpecialPawnProbability.LoadSettings(Ini: TIniFile);
begin
 Joker := ini.ReadInteger('Probabilities', 'Joker', 5);
 Bonus := ini.ReadInteger('Probabilities', 'Bonus', 5);
 Skull := ini.ReadInteger('Probabilities', 'Skull', 5);
 Chameleon := ini.ReadInteger('Probabilities', 'Chameleon', 5);
 Hourglass := ini.ReadInteger('Probabilities', 'Hourglass', 5);
end;

function TSpecialPawnProbability.GetDifficultLevelInPercent: Integer;
begin
 Result := 100 - Bonus - Joker + Skull;
end;

function TSpecialPawnProbability.GetSum;
begin
 Result := Joker + Bonus + Skull + Chameleon + Hourglass;
end;

function TSpecialPawnProbability.IsInJokerRange(e: double): boolean;
begin
 if Round(100*e) < Joker then Result := true
 else Result := false;
end;

function TSpecialPawnProbability.IsInBonusRange(e: double): boolean;
begin
 if (Round(100*e) >= Joker) and (Round(100*e) < Joker + Bonus) then Result := true
 else Result := false;
end;

function TSpecialPawnProbability.IsInSkullRange(e: double): boolean;
begin
 if (Round(100*e) >= Joker + Bonus) and (Round(100*e) < Joker + Bonus + Skull) then Result := true
 else Result := false;
end;

function TSpecialPawnProbability.IsInChameleonRange(e: double): boolean;
begin
 if (Round(100*e) >= Joker + Bonus + Skull) and (Round(100*e) < Joker + Bonus + Skull + Chameleon) then Result := true
 else Result := false;
end;

function TSpecialPawnProbability.IsInHourglassRange(e: double): boolean;
begin
 if (Round(100*e) >= Joker + Bonus + Skull + Chameleon) and (Round(100*e) < Joker + Bonus + Skull + Chameleon + Hourglass) then Result := true
 else Result := false;
end;

function TSpecialPawnProbability.GetJokerProbility: integer;
begin
 Result := Joker;
end;

function TSpecialPawnProbability.GetBonusProbility: integer;
begin
 Result := Bonus;
end;

function TSpecialPawnProbability.GetSkullProbility: integer;
begin
 Result := Skull;
end;

function TSpecialPawnProbability.GetChameleonProbility: integer;
begin
 Result := Chameleon;
end;

function TSpecialPawnProbability.GetHourglassProbility: integer;
begin
 Result := Hourglass;
end;

constructor TSpecialPawnProbability.Create(Joker, Bonus, Skull, Chameleon, Hourglass: integer);
begin
 self.Joker := Joker;
 self.Bonus := Bonus;
 self.Skull := Skull;
 self.Chameleon := Chameleon;
 self.Hourglass := Hourglass;
end;

end.
